package com.yiwenup.sorting;

import com.yiwenup.sorting._01_bubble.BubbleSortV1;
import com.yiwenup.sorting._01_bubble.BubbleSortV2;
import com.yiwenup.sorting._01_bubble.BubbleSortV3;
import com.yiwenup.sorting._02_selection.SelectionSort;
import com.yiwenup.sorting._03_heap.HeapSort;
import com.yiwenup.sorting._04_insertion.InsertionSortV1;
import com.yiwenup.sorting._04_insertion.InsertionSortV2;
import com.yiwenup.sorting._04_insertion.InsertionSortV3;
import com.yiwenup.sorting._05_merge.MergeSort;
import com.yiwenup.sorting._06_quick.QuickSort;
import com.yiwenup.sorting._07_shell.ShellSort;
import com.yiwenup.sorting._08_couting.CountingSortV2;
import com.yiwenup.sorting._09_radix.RadixSort;
import com.yiwenup.sorting.base.Sort;
import com.yiwenup.asserts.Asserts;
import com.yiwenup.sample.Integers;

import java.util.Arrays;

/**
 * 测试
 **/
@SuppressWarnings({"rawtypes", "unchecked"})
public class Main {
    public static void main(String[] args) {
        Integer[] array = Integers.random(50000, 1, 20000);
        testSorts(array,
                new BubbleSortV1(),
                new BubbleSortV2(),
                new BubbleSortV3(),
                new SelectionSort(),
                new HeapSort(),
                new InsertionSortV1(),
                new InsertionSortV2(),
                new InsertionSortV3(),
                new MergeSort(),
                new QuickSort(),
                new ShellSort(),
//                new CountingSortV1(),
                new CountingSortV2(),
                new RadixSort()
        );
    }

    public static void testSorts(Integer[] array, Sort... sorts) {
        for (Sort sort : sorts) {
            Integer[] copy = Integers.copy(array);
            sort.sort(copy);
            Asserts.test(Integers.isAscOrder(copy));
        }
        Arrays.sort(sorts);
        for (Sort sort : sorts) {
            System.out.println(sort);
        }
    }
}
